/*   
 * Copyright (c) 2010-2020 DMGIS Ltd. All Rights Reserved.   
 *   
 * This software is the confidential and proprietary information of   
 * DMGIS. You shall not disclose such Confidential Information   
 * and shall use it only in accordance with the terms of the agreements   
 * you entered into with DMGIS.   
 *   
 */
package com.dmgis.qxfw.dataservice.businessservice.common.util;

import java.awt.*;

/**
 * This class is used for 颜色处理类
 * 
 * @author dsq
 * @version 1.0, 2018年7月14日 上午11:10:28
 */
public class ColorUtil {

	/**
	 * 
	 * @return win32系统颜色转html颜色
	 * @author dsq
	 * @date 2018年7月14日
	 */
	public static String transWin32ToHtml(int color) {
		String htmlColor = "#ffffff";
		try {
			int r = color & 255;
			int g = color >> 8 & 255;
			int b = color >> 16 & 255;
			htmlColor = "#" + String.format("%02x", r) + String.format("%02x", g) + String.format("%02x", b);
		} catch (Exception e) {
			// TODO: handle exception
			System.out.println(e.getStackTrace());
		}
		return htmlColor;
	}

	public static String Color2String(Color color) {
		String R = Integer.toHexString(color.getRed());
		R = R.length() < 2 ? ('0' + R) : R;
		String G = Integer.toHexString(color.getGreen());
		G = G.length() < 2 ? ('0' + G) : G;
		String B = Integer.toHexString(color.getBlue());
		B = B.length() < 2 ? ('0' + B) : B;
		return '#' + R + G + B;
	}

	public static Color String2Color(String str) {
		int i = Integer.parseInt(str.substring(1), 16);
		return new Color(i);
	}
}
